package com.ruoyi.web.controller.members;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.members.domain.SysMembers;
import com.ruoyi.members.service.ISysMembersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员Controller
 * 
 * @author ruoyi
 * @date 2025-09-15
 */
@RestController
@RequestMapping("/system/members")
public class SysMembersController extends BaseController
{
    @Autowired
    private ISysMembersService sysMembersService;

    /**
     * 查询会员列表
     */
    @PreAuthorize("@ss.hasPermi('system:members:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysMembers sysMembers)
    {
        /*startPage();
        List<SysMembers> list = sysMembersService.selectSysMembersList(sysMembers);
        return getDataTable(list);*/


        Page<SysMembers> objectPage = new Page<>(sysMembers.getPageNum(),sysMembers.getPageSize());
        Page<SysMembers> page = sysMembersService.page(objectPage);
        return new TableDataInfo(page.getRecords(),page.getTotal(),page.getCurrent(),page.getSize());

    }

    /**
     * 导出会员列表
     */
    @PreAuthorize("@ss.hasPermi('system:members:export')")
    @Log(title = "会员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysMembers sysMembers)
    {
        List<SysMembers> list = sysMembersService.selectSysMembersList(sysMembers);
        ExcelUtil<SysMembers> util = new ExcelUtil<SysMembers>(SysMembers.class);
        util.exportExcel(response, list, "会员数据");
    }

    /**
     * 获取会员详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:members:query')")
    @GetMapping(value = "/{membersId}")
    public AjaxResult getInfo(@PathVariable("membersId") Long membersId)
    {
        return success(sysMembersService.selectSysMembersByMembersId(membersId));
    }

    /**
     * 新增会员
     */
    @PreAuthorize("@ss.hasPermi('system:members:add')")
    @Log(title = "会员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMembers sysMembers)
    {
        return toAjax(sysMembersService.insertSysMembers(sysMembers));
    }

    /**
     * 修改会员
     */
    @PreAuthorize("@ss.hasPermi('system:members:edit')")
    @Log(title = "会员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMembers sysMembers)
    {
        return toAjax(sysMembersService.updateSysMembers(sysMembers));
    }

    /**
     * 删除会员
     */
    @PreAuthorize("@ss.hasPermi('system:members:remove')")
    @Log(title = "会员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{membersIds}")
    public AjaxResult remove(@PathVariable Long[] membersIds)
    {
        return toAjax(sysMembersService.deleteSysMembersByMembersIds(membersIds));
    }
}
